//
//  BIZTopicTextCell.m
//  biz
//
//  Created by zhangfuwei on 2017/7/7.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZTopicTextCell.h"
#import "BIZHotTopicParentListModel.h"

@interface BIZTopicTextCell ()
/** title */
@property (nonatomic, strong) UILabel *titleLabel;
/** content */
@property (nonatomic, strong) UILabel *contentLabel;
/** time */
@property (nonatomic, strong) UIButton *timeButton;

@end

@implementation BIZTopicTextCell

#pragma mark - class method
+ (BIZTopicTextCell *)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
    BIZTopicTextCell *cell = [tableView dequeueReusableCellWithIdentifier:kTopicTextCellID forIndexPath:indexPath];
    
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initSubViews];
        
    }
    return self;
}

- (void)initSubViews {
    
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.contentLabel];
    [self.contentView addSubview:self.timeButton];
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(4);
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(7);
        make.left.right.equalTo(self.titleLabel);

    }];
    
    [_timeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLabel.mas_bottom).offset(15);
        make.height.equalTo(@37);
        make.bottom.left.right.equalTo(self.contentView);
    }];

}

#pragma mark -- set方法
-(void)setIssueModel:(BIZHotTopicParentListIssueModel *)issueModel {
    _issueModel = issueModel;
    _titleLabel.text = issueModel.topic;
    _contentLabel.text = issueModel.content;
    [_timeButton setTitle:[NSDate stringFromTimestamp:issueModel.createDate] forState:UIControlStateNormal];
    [self layoutIfNeeded];
}


#pragma mark -- lazyLoad
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.textColor = [UIColor zfw_ColorWithHex:0x333333 alpha:1.0];
        _titleLabel.font = [UIFont fontWithName:CHINESE_BOLD_FONT_NAME size:15];
        _titleLabel.numberOfLines = 2;
    }
    return _titleLabel;
}

- (UILabel *)contentLabel {
    if (!_contentLabel) {
        _contentLabel = [UILabel new];
        _contentLabel.textColor = [UIColor zfw_ColorWithHex:0x666666 alpha:1.0];
        _contentLabel.font = CHINESE_SYSTEM(14);
        _contentLabel.numberOfLines = 3;
    }
    return _contentLabel;
}

- (UIButton *)timeButton {
    if (!_timeButton) {
        _timeButton = [[UIButton alloc] init];
        
        _timeButton.layer.borderColor = [UIColor zfw_ColorWithHex:0xeeedee alpha:1.0].CGColor;
        _timeButton.layer.borderWidth = 1.0f;
        _timeButton.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
        _timeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        
        _timeButton.titleLabel.font = CHINESE_SYSTEM(10);
        [_timeButton setTitleColor:[UIColor zfw_ColorWithHex:0x999999 alpha:1.0] forState:UIControlStateNormal];
    }
    return _timeButton;
}

@end
